package com.jcode.skeleton.config;

/**
 * Created by haoyifen on 16-9-28 2016 下午5:43
 */

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class SwaggerConfig {

	@Bean
	public Docket createRestApi() {
		return new Docket(DocumentationType.SWAGGER_2)//
				.apiInfo(apiInfo())//
				.select()//
				.apis(RequestHandlerSelectors.basePackage("com.jcode"))//
				.paths(PathSelectors.any())//
				.build();
	}

	// https://my.oschina.net/dylw/blog/738188
	private ApiInfo apiInfo() {
		ApiInfo apiInfo = new ApiInfoBuilder()//
				.title("Swagger REST APIs")//
				.description("The Swagger APIs here demonstrate creating a service built with Spring Boot")//
				.license("Apache 2.0")//
				.licenseUrl("http://www.apache.org/licenses/LICENSE-2.0.html")//
				.contact(new Contact("dreajay", "blog.jc2w.com", "dreajay@163.com"))//
				.version("1.0")//
				.build();
		return apiInfo;
	}
}
